﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAOTicketReservationSystem;

namespace OnlineReservation
{
    public partial class WebFormPurchases : System.Web.UI.Page
    {
        private static int purchaseId = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            DivEdit.Visible = false;
        }

        protected void DropDownIds_SelectedIndexChanged(object sender, EventArgs e)
        {
            LinqDataSourcePurchases.Where = "PurchaseID == " + DropDownIds.SelectedValue.ToString();
        }

        protected void GridViewPurchases_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes["onmouseover"] =
                   "this.style.background='#EEEEEE';this.style.cursor='hand'";
                e.Row.Attributes["onmouseout"] =
                    "this.style.background='white'";

                LinkButton buttonEditStatus = e.Row.FindControl("ButtonEditStatus") as LinkButton;
                buttonEditStatus.CommandArgument = DataBinder.Eval(e.Row.DataItem, "PurchaseID").ToString();
            }
        }

        protected void ButtonEditStatus_Click(object sender, EventArgs e)
        {
            LinkButton linkButton = sender as LinkButton;
            purchaseId = int.Parse(linkButton.CommandArgument);
            DivEdit.Visible = true;
        }

        protected void ButtonCancel_Click(object sender, EventArgs e)
        {
            DivEdit.Visible = false;
        }

        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            Dao.EditPurchaseStatus(purchaseId, DropDownListStatus.Text);
            Response.Redirect("WebFormPurchases.aspx");
        }
    }
}